package org.ring.rpc;

import org.ring.common.utils.reflect.ServiceDescriptor;

import java.util.HashMap;
import java.util.Map;

/**
 * @since 2024-10-28 17:47
 */
public class ServiceRepository {

    private final static ServiceRepository INSTANCE = new ServiceRepository();
    private final Map<String, ServiceDescriptor> serviceDescriptorMap = new HashMap<>();
    private ServiceRepository(){

    }

    public static ServiceRepository getInstance(){
        return INSTANCE;
    }

    public ServiceDescriptor lookup(String interfaceName){
        return serviceDescriptorMap.get(interfaceName);
    }

    public synchronized void registerService(Class<?> serviceClass){
        ServiceDescriptor serviceDescriptor = new ServiceDescriptor(serviceClass);
        serviceDescriptorMap.put(serviceDescriptor.getInterfaceName(),serviceDescriptor);
    }
}
